import type { Module } from "vuex";
import type { RootState, SettingState, SetKeyValue } from "@model/store";

const setting: Module<SettingState, RootState> = {
	namespaced: true,
	state: {
		lang: "zh-cn", // 语言
		collapse: false, // 折叠 menu
		layoutSize: "small", // 全局 element-plus size
		openLogo: true, // 标题 logo
		keepHeader: true, // 固定头部
		keepTabs: true, // 固定tabs
		openTabs: true, // 开启tabs
		uniqueOpened: true, // 是否保持一个子菜单的展开
		openBreadcrumb: true, // 开启面包屑
		keepAside: false, // 固定 aside
		isHandleAsideFixed: false, // 是否 用户手动点击固定 aside
		navMode: "side", // 布局方式
		styleMode: "dark", // 风格
		routerTrans: "fade", // 路由动画
		asideMixinFixed: false, // asideMixin 固定
		mixinInverted: false, // mixin-aside 反转颜色 固定
		menuSegmentation: false, //菜单分割
	},
	getters: {
		lang: state => state.lang,
		collapse: state => state.collapse,
		layoutSize: state => state.layoutSize,
		openLogo: state => state.openLogo,
		keepHeader: state => state.keepHeader,
		keepTabs: state => state.keepTabs,
		openTabs: state => state.openTabs,
		uniqueOpened: state => state.uniqueOpened,
		openBreadcrumb: state => state.openBreadcrumb,
		keepAside: state => state.keepAside,
		isHandleAsideFixed: state => state.isHandleAsideFixed,
		navMode: state => state.navMode,
		styleMode: state => state.styleMode,
		routerTrans: state => state.routerTrans,
		asideMixinFixed: state => state.asideMixinFixed,
		mixinInverted: state => state.mixinInverted,
		menuSegmentation: state => state.menuSegmentation,
	},
	mutations: {
		// 初始化配置
		SET_INIT(state) {
			state.lang = "zh-cn";
			state.collapse = false;
			state.layoutSize = "small";
			state.openLogo = true;
			state.keepHeader = true;
			state.keepTabs = true;
			state.openTabs = true;
			state.uniqueOpened = true;
			state.openBreadcrumb = true;
			state.keepAside = false;
			state.isHandleAsideFixed = false;
			state.navMode = "side";
			state.styleMode = "dark";
			state.routerTrans = "fade";
			state.asideMixinFixed = false;
			state.mixinInverted = false;
			state.menuSegmentation = false;
		},
		// 设值
		SET_SETTING(state, { key, value }: SetKeyValue) {
			state[key] = value;
		},
	},
	actions: {
		SET_INIT({ commit }) {
			commit("SET_INIT");
		},
		SET_SETTING({ commit }, value: SetKeyValue) {
			commit("SET_SETTING", value);
		},
	},
};

export default setting;
